import { Button, Form, type FormInstance, type FormProps, Space } from 'antd';
import type { ReactNode } from 'react';

// 利用 FormProps 继承 antd Form 的所有属性
interface SearchFormProps extends FormProps {
    form?: FormInstance;
    initialValues?: Record<string, any>;
    submit?: () => void;
    reset?: () => void;
    children?: ReactNode;
}

/**
 * 搜索表单容器组件封装
 * @param props
 * @returns
 */
export default function SearchForm({
    form,
    initialValues,
    submit = () => {},
    reset = () => {},
    children,
    ...rest
}: SearchFormProps) {
    return (
        <Form
            className="search-form"
            form={form}
            layout="inline"
            initialValues={initialValues}
            {...rest}
        >
            {children}
            <Form.Item>
                <Space>
                    <Button
                        type="primary"
                        onClick={submit}
                    >
                        搜索
                    </Button>
                    <Button
                        type="default"
                        onClick={reset}
                    >
                        重置
                    </Button>
                </Space>
            </Form.Item>
        </Form>
    );
}
